
package com.example.testutil.util;

import java.util.Stack;

import android.app.Activity;

public class ActivityManager {

    private static volatile ActivityManager instance;

    private Stack<Activity> mActivities = new Stack<>();

    private ActivityManager() {
    }

    public static ActivityManager getInstance() {
        if (instance == null) {
            synchronized (ActivityManager.class) {
                if (instance == null) {
                    instance = new ActivityManager();
                }
            }
        }
        return instance;
    }

    public void addActivity(Activity act) {
        mActivities.add(act);
    }

    public void removeActivity(Activity act) {
        mActivities.remove(act);
    }

    public void killMyProcess() {
        int count = mActivities.size();
        for (int i = 0; i < count; i++) {
            Activity activity = mActivities.get(i);
            activity.finish();
        }
        mActivities.clear();
        android.os.Process.killProcess(android.os.Process.myPid());
    }

}
